/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sourceryobjects;

import java.awt.geom.Point2D;
import java.io.Serializable;

/**
 *
 * @author claire
 */
public class sPoint implements Cloneable, Serializable {
    private double x,y;

    public sPoint(double x, double y) {
        this.x = x;
        this.y = y;
    }
    public sPoint(Point2D a) {
        this.x = a.getX();
        this.y = a.getY();
    }
    public sPoint(sPoint a) {
        this.x = a.x;
        this.y = a.y;
    }

    public double distance(sPoint p) {
        double dx = p.x - x;
        double dy = p.y - y;
        return Math.sqrt(dx*dx+dy*dy);
    }

    public double distance2(sPoint p) {
        double dx = p.x - x;
        double dy = p.y - y;
        return dx*dx+dy*dy;
    }

    public double length() {
        return Math.sqrt(x*x+y*y);
    }
    public double length2() {
        return x*x+y*y;
    }

    public void add(sPoint b) {
        x += b.x;
        y += b.y;
    }
    public void set(sPoint b) {
        x = b.x;
        y = b.y;
    }

    public sPoint normal() {
        return new sPoint(x/length(), y/length());
    }

    public sPoint plus(sPoint b) {
        return new sPoint(x + b.x, y + b.y);
    }
    public sPoint minus(sPoint b) {
        return new sPoint(x - b.x, y - b.y);
    }

    public sPoint plus(Point2D b) {
        return new sPoint(x + b.getX(), y + b.getY());
    }

    public sPoint scale(double b) {
        return new sPoint(x *b, y*b);
    }
    public sPoint opposite() {
        return new sPoint(-x,-y);
    }

    public double getX() {
        return x;
    }
    public double getY() {
        return y;
    }

    public Point2D getPoint2D() {
        
        return new Point2D.Double(x,y);
    }
    public double getAngleR() {
        return Math.atan2(y, x);
    }
    public double getAngleD() {
        return Math.toDegrees(getAngleR());
    }

}
